package com.shop.cloud.controller.hongfu;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.shop.cloud.common.mybatis.BaseController;
import com.shop.cloud.domain.hongfu.PointsConfig;
import com.shop.cloud.domain.hongfu.User;
import com.shop.cloud.filter.CurrentUserId;
import com.shop.cloud.model.response.ObjectDataResponse;
import com.shop.cloud.service.hongfu.IPointsConfigService;
import com.shop.cloud.service.hongfu.IUserService;

import io.swagger.annotations.ApiOperation;

/**
 * 积分管理
 * @author Yan Weiwei
 *
 */
@RestController	
@RequestMapping(value = "api")
public class PointsManageController extends BaseController {
	
	@Autowired
	private IUserService userService;
	
	@Autowired
	private IPointsConfigService pointsConfigService;

	@ApiOperation(value = "用户赠送积分", notes = "用户赠送积分")
	@RequestMapping(value = "/givingPoints", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Integer> givingPoints(@CurrentUserId Long userId, @RequestBody User user){
		
		int result = userService.handleUserGivingPoints(userId, user);
		
		return new ObjectDataResponse<Integer>(result);
	}
	
	@ApiOperation(value = "获取积分比例", notes = "获取积分比例")
	@RequestMapping(value = "/getPointsConfig", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<PointsConfig> getPointsConfig(@CurrentUserId Long userId){
		
		PointsConfig pointsConfig = pointsConfigService.get(new Long(1));
		
		return new ObjectDataResponse<PointsConfig>(pointsConfig);
	}
}
